package cn.utile;

import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.builder.fluent.Configurations;
import org.apache.commons.configuration2.ex.ConfigurationException;

import java.util.Iterator;
import java.util.List;
import java.util.Properties;


public class XmlParsing {

    private Configuration systemConfigXML = null;

    public XmlParsing() {

        if (systemConfigXML == null) {
            try {

                Configurations cfg = new Configurations();
                systemConfigXML = cfg.xml(XmlParsing.class.getResource("/").getPath() + "/" + "employee-msg.xml");
            } catch (ConfigurationException cfe) {
                System.out.println("获取配置异常！" + cfe.getMessage());
            }
        }

    }

    public Configuration getSystemConfigXML() {
        return systemConfigXML;

    }


    public static void main(String[] args) {
        XmlParsing xmlParsing = new XmlParsing();
        Configuration configuration = xmlParsing.getSystemConfigXML();
        List<Object> mouth = configuration.getList("month[@value]");
        System.out.println(mouth);

        for (int i = 0; i < mouth.size(); i++) {
            System.out.println("月份==============" + mouth.get(i));
            List<Object> names = configuration.getList("month(" + i + ").employee[@name]");
            for (int k = 0; k < names.size(); k++) {
                Object name = names.get(k);
                String type =configuration.getString("month(" + i + ").employee(" + k + ")[@type]");
                String birthday =configuration.getString("month(" + i + ").employee(" + k + ")[@birthday]");
                System.out.print("员工姓名：" + name);
                System.out.print("    岗位类型：" + type);
                System.out.println("    出生日期：" + birthday);
                if("salary".equals(type)){

                }else if("hour".equals(type)){

                }else if("sale".equals(type)){

                }else {
                    System.out.println("    位置岗位类型" + type);
                }


            }


        }


//        Iterator<String> values =configuration.getKeys("month[@value]");
//        int i = 0 ;
//        while(values.hasNext()){
//            System.out.println(values.next());
//            List<Object> employee  =configuration.getList("month("+i+").employee");
//            System.out.println(employee);
//        }
    }
}
